<!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>[Boost].SML - State Machine Language</title>

		<meta name="description" content="Concepts driven design with dependency injection">
		<meta name="author" content="Kris Jusiak">

		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">

		<link rel="stylesheet" href="css/reveal.css">
        <link rel="stylesheet" href="css/theme/league.css" id="theme">

            <!-- Code syntax highlighting -->
        <link rel="stylesheet" href="lib/css/zenburn.css">

		<!-- Printing and PDF exports -->
		<script>
			var link = document.createElement( 'link' );
			link.rel = 'stylesheet';
			link.type = 'text/css';
			link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
			document.getElementsByTagName( 'head' )[0].appendChild( link );
		</script>

		<!--[if lt IE 9]>
		<script src="lib/js/html5shiv.js"></script>
		<![endif]-->
	</head>

	<body>

		<div class="reveal">
			<div class="slides">

          <section data-markdown=""
                   data-separator="^====+$"
                   data-separator-vertical="^----+$"
                   data-notes="^Note:">
					<script type="text/template">
#### C++ Now 2017
# [Boost].SML
# State Machine Language
<!-- .element: style="margin-left:-13%; width:125%" -->

Kris Jusiak, Quantlab Financial

---

[kris@jusiak.net](mailto:kris@jusiak.net) | [@krisjusiak](https://twitter.com/krisjusiak) | [linkedin.com/in/kris-jusiak](https://www.linkedin.com/in/kris-jusiak)

==============================================================================

## Connection - State Diagram

![Connection](images/connection.png)

#### Unified Modeling Language (UML 2.5)

----

### Connection - State Diagram - Transition

![](images/transition_table.png)

#### Transition

![Transition](images/transition.png)

----

### [[Boost].SML](http://boost-experimental.github.io/sml) - Connection

```cpp
// guards
const auto is_valid = [](auto event) { return event.valid; };

// actions
const auto establish = [] { std::puts("establish"); };
const auto close = [] { std::puts("close"); };
const auto resetTimeout = [] { std::puts("resetTimeout"); };

// events (types)
struct connect {}; // ...
struct ping { bool valid{}; };
```
<!-- .element: style="width:105%" -->

```cpp
int main() {
  sml::sm connection = [] {
    return transition_table{
      * "Disconnected"_s + connect / establish                = "Connecting"_s,
        "Connecting"_s   + established                        = "Connected"_s,
        "Connected"_s    + ping [ is_valid ] / resetTimeout,
        "Connected"_s    + timeout / establish                = "Connecting"_s,
        "Connected"_s    + disconnect / close                 = "Disconnected"_s
    };
  };

  sm.process_event(connect{});
}
```
<!-- .element: style="width:105%" -->

----

### [[Boost].SML](http://boost-experimental.github.io/sml) - Performance

| |
|-|
| <a href="https://godbolt.org/e#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAKxAEZSBnVAV2OUxAHIBSAJgGY8AO2QAbZlgDU3fgGEEBAgAcGIAPRriAQwDuAOmCEEzAEbMGmNqiEFMNvWgC2ak6lQMCAWkwAPJZbxHOwItUTUGRzDHLQ9LNWExCUwXNw9wyL0EJSUZbG4ABgBBPkERcSkZWWQPfFRcguKioS0ghiUtdkkI0Wl%2BABFJV3cCEBBumQAhBoaPYmZkAkk0ISFMBekAdimNvsmZgjn1pWFgTYnBtx6AN1C8dF6BgDNQi0nN3f4potn5xcwPLQmUR4BgITD3bhbSEfL6FH7rAiBTAsRaQ7Yw/aHRb4BjLVbrNHQvZFBrLDySLTMIiSf4hIEghAPaQAVimzN2Wy6BHQoyUVIYED4vFpgOBoKFAEo3kTPqTrOTKdSxO5MEzuKz1RzzjVefzBbxeMrXgapZ93sTCmTForUJIQQB9G7AiH9FlsvoQK0Uql1XgANhpV2CErOkmImAIrCEgeCeidd2lOwtXptYf%2BEYAKkiUWqNezQzqQHyCAKheGLAQs0EUZLExiSd8Dr9JLJrPjEdYzg1JN7qah/NoiMQIBKR0t5aioUUez3zCdJM1Wu1OuNZdOZ%2BHI8Ro9EANaYe0HLRCBiEPDWQ%2BizCC9czyQAKmkBr6ILxa1s6CF9oYT/OmCDNiVG%2BCy5JIag0gC9KgneMGwWqBqtis74nF%2BDCkN2cFCoh7YoQa34znwf4AQQlQilBYKfvw2BwTRtEyAMWFtu%2B4Koeht4wYxSELCxeE/gRvBEcElTHEIwCgeq5wOvGEL5uB5aZtmVJsYUNGce2PG8Ph/GCYBciItWVKgeBZFioytGwfRT68NhyGiaxGEWQhTHcZ%2BvF3oRMa6bIOLASRVFgUsogquZmGukKL64s5H6oQ5kimrCPZEiSSZro0hTCIs0TCGOhLrt0owRJUNkLOeQigb5pWEilCXSOuFXWHoSjEKg7AMAw9r/sEnpRVVfTxRh9VCI1zWte1nU2BAJkMixUI7P1dVRaVw0tf8Y3ERAIliVsTaYNC80qeOXEdkNTUrW1HXrT5PWzX1FpJWlDScBKpCiFwzKcKQQhcPkH2oFwsiER5TCsJ0JS0B9IycD9ErPbuIB%2BrQej8MytAAJwACwbPkqMbBsBr%2Bi9XDox9X1Q79XAfao%2BSkJD0OkHAsBIE4xyiJY5CUMzeCs8QKCiMewDo/k1OPFztjEKoEAmN9H1OEENgAPJCKIACe0ukPg4YlUGqhk89/bHTrnjy/wkieH0AByfTYBMACqADips1PRyCAwJtAAF6UywbAcLQz2vZw72fWrf2cD4AAcfqeH66OBfzkjo3o%2BRJ5IEC4IQJBPvw9Atqgjgs5YWd%2BxD0sw6QcP8OHegx%2BH%2BTMrwqP5AauMbOjhOcMTpCOHQQvB2TpCh5TIDU7TT3%2B1wvAkyHFM06Xz1BuLpUgOjQA%3D%3D%3D"><img style="background:none; border:none; box-shadow:none;" src="images/performance.png" /></a> |
<!-- .element: style="margin-left:-18%; width:135%" -->

----

##[benchmark](https://github.com/boost-experimental/sml/tree/master/benchmark/complex) - Results

<img style="background:none; border:none; box-shadow:none;" src="images/benchmark.png" width="140%" />

==============================================================================

## [[Boost].SML](http://boost-experimental.github.io/sml) / Questions?

* One header - 2k LOC - (boost/sml.hpp) / generated
* Neither Boost nor STL is required
* Quick compilation-times (-Wall -Wextra -Werror -pedantic -pedantic-errors)
* Blazing fast run-time (Generated at compile-time)
* No 'virtual's (-fno-rtti)
* Optional support for 'exception's (-fno-exceptions)
* Supported compilers (C++14)
  * [Clang-3.4+](https://travis-ci.org/boost-experimental/sml), [XCode-6.1+](https://travis-ci.org/boost-experimental/sml), [GCC-5.2+](https://travis-ci.org/boost-experimental/di), [MSVC-2015+](https://ci.appveyor.com/project/krzysztof-jusiak/sml)

---

https://github.com/boost-experimental/sml
					</script>
				</section>

			</div>
		</div>

		<script src="lib/js/head.min.js"></script>
		<script src="js/reveal.js"></script>

		<script>

			// Full list of configuration options available at:
			// https://github.com/hakimel/reveal.js#configuration
			Reveal.initialize({

        // Display controls in the bottom right corner
        controls: true,

        // Display a presentation progress bar
        progress: true,

        // Display the page number of the current slide
        slideNumber: true,

        // Push each slide change to the browser history
        history: true,

        // Enable keyboard shortcuts for navigation
        keyboard: true,

        // Enable the slide overview mode
        overview: true,

        // Vertical centering of slides
        center: true,

        // Enables touch navigation on devices with touch input
        touch: true,

        // Loop the presentation
        loop: false,

        // Change the presentation direction to be RTL
        rtl: false,

        // Turns fragments on and off globally
        fragments: false,

        // Flags if the presentation is running in an embedded mode,
        // i.e. contained within a limited portion of the screen
        embedded: false,

        // Flags if we should show a help overlay when the questionmark
        // key is pressed
        help: true,

        // Flags if speaker notes should be visible to all viewers
        showNotes: false,

        // Number of milliseconds between automatically proceeding to the
        // next slide, disabled when set to 0, this value can be overwritten
        // by using a data-autoslide attribute on your slides
        autoSlide: 0,

        // Stop auto-sliding after user input
        autoSlideStoppable: true,

        // Enable slide navigation via mouse wheel
        mouseWheel: true,

        // Hides the address bar on mobile devices
        hideAddressBar: true,

        // Opens links in an iframe preview overlay
        previewLinks: false,

        // Transition style
        transition: 'convex', // none/fade/slide/convex/concave/zoom

        // Transition speed
        transitionSpeed: 'default', // default/fast/slow

        // Transition style for full page slide backgrounds
        backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom

        // Number of slides away from the current that are visible
        viewDistance: 3,

        // Parallax background image
        parallaxBackgroundImage: '', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'"

        // Parallax background size
        parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px"

        // Number of pixels to move the parallax background per slide
        // - Calculated automatically unless specified
        // - Set to 0 to disable movement along an axis
        parallaxBackgroundHorizontal: null,
        parallaxBackgroundVertical: null,

				// Optional reveal.js plugins
				dependencies: [
					{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
					{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
					{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
					{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
					{ src: 'plugin/zoom-js/zoom.js', async: true },
					{ src: 'plugin/notes/notes.js', async: true }
				]
			});

		</script>

	</body>
</html>
